package summer.codegenerator.persistence.hibernate.base.tool;

import java.io.Serializable;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

/**
 * 
 * 
 * @author 蒋振
 * @since 2019年7月3日 上午8:58:49
 */
public class Sort implements Serializable {

	private static final long serialVersionUID = 1L;

	private static final String ASC = "asc";

	private static final String DESC = "desc";

	/**
	 * 是否升序
	 *  true    升序
	 *  false   倒序
	 */
	private Boolean ascending;

	private List<String> sortPropNames;

	public Boolean getAscending() {
		return ascending;
	}

	public void setAscending(Boolean ascending) {
		this.ascending = ascending;
	}

	public List<String> getSortPropNames() {
		return sortPropNames;
	}

	public void setSortPropNames(List<String> sortPropNames) {
		this.sortPropNames = sortPropNames;
	}

	public String getClause() {
		return " order by " + StringUtils.join(sortPropNames, ",") + " " + (ascending ? ASC : DESC);
	}
}
